import cv2
import os

current_directory = os.path.dirname(__file__)
pic = os.path.join(current_directory, "yellow.png")

def get_hsv(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
        hsv_value = hsv[y, x]
        print(f"HSV 值: {hsv_value} 位置: ({x}, {y})")

image = cv2.imread(pic)

# 获取图像宽高
height, width = image.shape[:2]

# 创建可调节大小的窗口
cv2.namedWindow('light contours', cv2.WINDOW_NORMAL)
# 设置窗口大小为图像的大小
cv2.resizeWindow('light contours', width, height)
cv2.setMouseCallback('light contours', get_hsv)

cv2.imshow('light contours', image)
cv2.waitKey(0)
cv2.destroyAllWindows()